﻿//改良版多级菜单收缩
function myhid()
{
	var allTags=document.getElementById("list").getElementsByTagName("dd");
	for (var i=0; i<allTags.length; i++){
		allTags[i].className="";
	}
}

function myshow (event) 
{
	var e = event || window.event; 
	var src = e.srcElement || e.target;
	nextSib = src.nextSibling;
	while (nextSib.nodeType != 1) 
	{
		nextSib = nextSib.nextSibling; 
	}
	if (nextSib.className == 'vis')
	{
		nextSib.className='';
	}
	else
	{
		myhid()
		nextSib.className = 'vis'; 
	}
} 

//判断是否刷新页面
function addupdate(itemid) {
	if (itemid<0)
		update_body('-100')
}

//ajax
function update_body(itemid) {
  if (itemid < 0)
  	ReturnURL="/budget/rgf/"+itemid+"/"
  else
  	ReturnURL="/budget/"+itemid+"/"
  htmlobj=$.ajax({url:ReturnURL,cache:false,async:false});
  $("#div_body").html(htmlobj.responseText);
}

// 改变菜单背景颜色
function changeBgColor(TagID) {
	var allTags=document.getElementById("list").getElementsByTagName("p");
	for (var i=0; i<allTags.length; i++){
    allTags[i].className="";
    }
  TagID.className="bgcolor";
}

// 图表
function GetPic() {
	var options ={
		chart: {
			renderTo: 'container',
			plotBackgroundColor: null,
			plotBorderWidth: null,
			plotShadow: false,
			margin : [ 20, 150, 10, 100 ]
		},
		title: {text: ''},
		tooltip: {
			formatter: function() {
				return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.y, 0, ',') +' 元';
			}
		},
		plotOptions: {
			pie: {
				allowPointSelect: true,
				cursor: 'pointer',
				dataLabels: {
					enabled: true,
					color: '#000000',
					connectorColor: '#000000',
					formatter: function() {
						return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
					}
				},
				showInLegend: true
			}
		},
		legend:{
			layout: 'vertical',	//图例显示的样式：水平（horizontal）/垂直（vertical）
			backgroundColor:null,
			x:300,
			y:100,
			align: 'center',
			verticalAlign: 'right',
			enabled:true
		},
		credits: {
			enabled:false
		},
		series: [{
			type: 'pie',
			name: 'mytest',
			data: []
		}]
	};
	
	jQuery.get('/budget/picdata/', null, function(tsv, state, xhr) {
			var mydata,
			// set up the two data series
			allVisits = [];
			// inconsistency
			if (typeof tsv !== 'string') {
				tsv = xhr.responseText;
			}
			// split the data return into lines and parse them
			tsv = tsv.split(/\n/g);
			jQuery.each(tsv, function(i, line) {
				// all data lines start with a double quote
				line = line.split(/\t/);
				mydata = line[0]
				allVisits.push([
					mydata, 
					parseInt(line[1])
				]);
			});
			options.series[0].data = allVisits;
			chart = new Highcharts.Chart(options);
		}
	);
}
